package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.tradeapplicationinvoice.LindiTradeApplicationInvoiceQueryVO;
import com.minimalist.common.entity.lindi.vo.tradeapplicationinvoice.LindiTradeApplicationInvoiceVO;
import com.minimalist.common.response.R;

import java.util.List;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.service.LindiTradeApplicationInvoiceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 林地指标交易平台_交易申请发票控制器
 *
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_交易申请发票管理")
@RequestMapping("/lindi/tradeApplicationInvoice")
public class LindiTradeApplicationInvoiceController{

    @Autowired
    private LindiTradeApplicationInvoiceService service;

    @PostMapping("/addTradeApplicationInvoice")
    @Operation(summary = "添加交易申请发票")
    public R<?> addTradeApplicationInvoice(
            @RequestBody @Validated(Add.class)
            LindiTradeApplicationInvoiceVO tradeApplicationInvoiceVO){
        service.addTradeApplicationInvoice(tradeApplicationInvoiceVO);
        return R.ok();
    }

    @DeleteMapping("/deleteTradeApplicationInvoiceByTradeApplicationInvoiceId")
    @Operation(summary = "删除交易申请发票 -> 根据交易申请发票ID删除")
    public R<?> deleteTradeApplicationInvoiceByTradeApplicationInvoiceId(
            @RequestParam("tradeApplicationInvoiceId")
            @NotNull(message = "交易申请发票ID不能为空")
            @Parameter(name = "tradeApplicationInvoiceId", required = true, description = "交易申请发票ID")
            Long tradeApplicationInvoiceId){
        service.deleteTradeApplicationInvoiceByTradeApplicationInvoiceId(
                tradeApplicationInvoiceId);
        return R.ok();
    }

    @PutMapping("/updateTradeApplicationInvoiceByTradeApplicationInvoiceId")
    @Operation(summary = "修改交易申请发票")
    public R<?> updateTradeApplicationInvoiceByTradeApplicationInvoiceId(
            @RequestBody @Validated(Update.class)
            LindiTradeApplicationInvoiceVO tradeApplicationInvoiceVO){
        service.updateTradeApplicationInvoiceByTradeApplicationInvoiceId(
                tradeApplicationInvoiceVO);
        return R.ok();
    }

    @GetMapping("/getPageTradeApplicationInvoiceList")
    @Operation(summary = "查询交易申请发票列表(分页)")
    public R<PageResp<LindiTradeApplicationInvoiceVO>> getPageTradeApplicationInvoiceList(
            @RequestBody LindiTradeApplicationInvoiceQueryVO queryVO){
        return R.ok(service.getPageTradeApplicationInvoiceList(queryVO));
    }

    @GetMapping("/getTradeApplicationInvoiceByTradeApplicationInvoiceId/{tradeApplicationInvoiceId}")
    @Operation(summary = "根据交易申请发票ID查询交易申请发票")
    public R<LindiTradeApplicationInvoiceVO> getTradeApplicationInvoiceByTradeApplicationInvoiceId(
            @PathVariable(value = "tradeApplicationInvoiceId")
            @NotNull(message = "交易申请发票ID不能为空")
            @Parameter(name = "tradeApplicationInvoiceId", description = "交易申请发票ID", required = true)
            Long tradeApplicationInvoiceId){
        return R.ok(service.getTradeApplicationInvoiceByTradeApplicationInvoiceId(
                tradeApplicationInvoiceId));
    }

    @GetMapping("/getTradeApplicationInvoiceListByTradeApplicationId")
    @Operation(summary = "根据交易申请ID查询发票列表")
    public R<List<LindiTradeApplicationInvoiceVO>> getTradeApplicationInvoiceListByTradeApplicationId(
            @RequestParam("tradeApplicationId")
            @NotNull(message = "交易申请ID不能为空")
            @Parameter(name = "tradeApplicationId", required = true, description = "交易申请ID")
            Long tradeApplicationId) {
        return R.ok(service.getTradeApplicationInvoiceListByTradeApplicationId(tradeApplicationId));
    }
}